--with c_arbre;  
with ada.text_io; use ada.text_io;
package body reconeixedor is

procedure shift(exp: in out expr) is
  begin
put(exp.v(exp.n));
    exp.n:= exp.n + 1;
end shift;


--procedure rec_exp_ini(exp: in out expr; e: in out arbre) is
procedure rec_exp_ini(exp: in out expr) is
e: arbre;
  begin
    rec_exp(exp, e);
  if exp.v(exp.n) /= ';' then
	put("hi havia: ");
	put(exp.v(exp.n));
--      raise semicolon_error;
  end if;
  end rec_exp_ini;


procedure rec_exp(exp: in out expr; e: in out arbre) is
ex, fx: arbre;
op: character:=' ';
begin
	put_line("Comença reconeixement expressió");
--  shift(exp);
	rec_term(exp, ex);
	while ((exp.v(exp.n) = '+') or (exp.v(exp.n) = '-')) loop
		op:= exp.v(exp.n); shift(exp);
		rec_term(exp, fx);
		e:= empelta(op, ex, fx);
	end loop;
end rec_exp;


procedure rec_term(exp: in out expr; t: in out arbre) is
op: character:=' ';
ex, fx: arbre;
begin
	put_line("Comença reconeixement termes");
  --  shift(exp);
	rec_fact(exp, ex);
	while ((exp.v(exp.n) = '*') or (exp.v(exp.n) = '/')) loop
		op:= exp.v(exp.n); shift(exp);
		rec_fact(exp, fx);
		t:= empelta(op, ex, fx); -- ?
	end loop;
end rec_term;



procedure rec_fact(exp: in out expr; f: in out arbre) is
i: index:= lliure;
begin
	put_line("Comença reconeixement factors");
--	shift(exp);
		if (('0' <= exp.v(exp.n) and exp.v(exp.n) <= '9') or (exp.v(exp.n) = 'x')) then
			--lliure:= m(lliure).s;
			posa(f, exp.v(exp.n));
			--m(i).val:= exp.v(exp.n);
			shift(exp);
		end if;
		if (exp.v(exp.n) = '(')  then 
			shift(exp); rec_exp(exp, f); shift(exp);
		end if;

--    shift(exp);
end rec_fact;


procedure list_all2 is
begin
list_all;
end list_all2;


end reconeixedor;
